package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.domain.Student;
import com.itheima.service.StudentService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stu")
public class StudentController {

    @Reference
    private StudentService studentService;

    @RequestMapping("/findAll")
    public PageInfo<Student> findAll(@RequestParam(defaultValue = "1",required = false) Integer currentPage,
                                     @RequestParam(defaultValue = "5",required = false) Integer pageSize){
        PageInfo<Student> all = studentService.findAll(currentPage, pageSize);
        return all;
    }

    @RequestMapping("/add")
    public void save(@RequestBody Student student){
        studentService.save(student);
    }

    @RequestMapping("/deleteStu")
    public void delete(@RequestParam String number){
        studentService.delete(number);
    }

    @RequestMapping("updateStu")
    public void update(@RequestBody Student student){
        studentService.update(student);
    }
}
